package com.scs.application.modules.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.base.entity.Patient;
import com.scs.application.modules.base.service.PatientService;
import com.scs.application.modules.cfg.utils.ParameterUtils;
import com.scs.application.modules.sys.model.PageResult;
import com.scs.application.modules.thirdparty.request.view.his.HisReqServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/base/patient")
public class PatientController extends CrudController<PatientService, Patient>{
    @Autowired
    HisReqServiceImpl hisReqViewService;

    /**
     * 选择时使用
     */
    @GetMapping("/pageForSelect")
    public PageResult pageForSelect() {
        QueryContext queryContext = QueryContextHolder.currentContext();
        IPage pageResult;
        if (ParameterUtils.isPatientSelectHisView()) {
            pageResult = hisReqViewService.patientPage(queryContext);
        } else {
            pageResult = service.page(queryContext);
        }
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }
}
